package com.sk.bilibili.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sk.bilibili.bean.FollowThem;
import com.sk.bilibili.dto.FollowThemInfo;
import com.sk.bilibili.other.R;
import com.sk.bilibili.service.FollowThemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
* @author 邵康
* @date 2021/11/24 09:40
*/
@CrossOrigin
@RestController
@RequestMapping("/followThem")
@Api(tags = "追番")
public class FollowThemController {

    @Autowired
    private FollowThemService followThemService;

    @ApiOperation("添加追番themId必须     0想看  1 在看   2  看过  默认1")
    @PostMapping("/add")
    public R<FollowThem> add(@RequestBody FollowThem followThem){
        return followThemService.add(followThem);
    }

    @ApiOperation("获取追番信息  都不是必须的")
    @PostMapping("/getFollowThem")
    public R<IPage<FollowThem>> getFollowThem(@RequestBody FollowThemInfo followThemInfo){
        return followThemService.getFollowThem(followThemInfo);
    }

    @ApiOperation("更新状态,若状态为null取消追番")
    @GetMapping("/updateState")
    public R<Void> updateState(Integer id,@RequestParam(required = false) Integer state){
        return followThemService.updateState(id,state);
    }

    @ApiOperation("deleteRes")
    @GetMapping("/delete")
    public R<Void> delete(Integer id){
        return followThemService.delete(id);
    }

    @ApiOperation("update")
    @PostMapping("/update")
    public R<Void> update(@RequestBody FollowThem followThem){
        return followThemService.update(followThem);
    }

    @ApiOperation("pageSearch")
    @GetMapping("/page")
    public R<IPage<FollowThem>> page( @RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer size){
        return followThemService.page(page,size);
    }

}
